package de.traveltainment.concept.envers.updaters;

import de.traveltainment.concept.envers.audit.lifecycle.Stage;
import de.traveltainment.concept.envers.entities.Provider;
import de.traveltainment.concept.envers.entities.Vito;
import de.traveltainment.concept.envers.repository.ProviderRepository;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * Created by borlis on 13.06.2014.
 */
@RequestScoped
public class ConfigurationProviderBuilder {

    private Vito vito;
    private Integer numberOfProviders;
    private Stage stage;

    @Inject
    private ProviderRepository providerRepository;

    @Inject
    private Logger logger;

//    public void build() {
//        for (int i = 0; i < numberOfProviders; i++) {
//            String randomizer = rundomPrefix();
//            Provider provider = createProvider();
//            provider = providerRepository.create(provider);
//            logger.log(Level.INFO, ""+i+"th iteration .. ");
//            logger.log(Level.INFO, "provider: "+provider.toString());
//        }
//    }


    public Provider createProvider(String country){
        String randomizer = rundomPrefix();
        Provider provider = new Provider();
        provider.setName("provider_" + stage+"_"+randomizer);
        provider.setCountry(country);
        provider.setCode("PRV_" + stage + "_" + randomizer);
        return provider;
    }

    private String rundomPrefix() {
        return "" + (int) (Math.random() * 200000);
    }

    public void setVito(Vito vito) {
        this.vito = vito;
    }

    public void setVersion(Stage version) {
        this.stage = version;
    }

    public void setNumberOfProviders(Integer numberOfProviders) {
        this.numberOfProviders = numberOfProviders;
    }

}
